package com.credit.context;


import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.credit.entity.CreditUserInfo;
import com.credit.web.basic.bean.ResBean;




public class CreditServletContext {
	
	private static ThreadLocal<HttpServletRequest> requestThreadLocal = new ThreadLocal<HttpServletRequest>();
	
	private static ThreadLocal<HttpServletResponse> responseThreadLocal = new ThreadLocal<HttpServletResponse>();
	
	private static ThreadLocal<CreditUserInfo> userInfoThreadLocal = new ThreadLocal<CreditUserInfo>();
	
	private static ThreadLocal<ResBean> resBeanThreadLocal = new ThreadLocal<ResBean>();
	
	private static ThreadLocal<String> tokenThreadLocal = new ThreadLocal<String>();
	
	private static ThreadLocal<Map<String,String>> scopeLocal = new ThreadLocal<Map<String,String>>();
	
	
	/*--------------------------------------------------------------------------------------------*/
	
	
	public static void setHttpServlet(HttpServletRequest request,HttpServletResponse response){
		requestThreadLocal.set(request);
		responseThreadLocal.set(response);
	}
	
	public static HttpServletRequest getRequest(){
		return requestThreadLocal.get();
	}
	
	public static HttpServletResponse getResponse(){
		return responseThreadLocal.get();
	}
	
	
	public static ResBean getResBean(){
		return resBeanThreadLocal.get();
	}
	
	public static void setResBean(ResBean resBean){
		resBeanThreadLocal.set(resBean);
	}
	
	
	public static CreditUserInfo getUserInfo(){
		return userInfoThreadLocal.get();
	}
	
	public static void setUserInfo(CreditUserInfo userInfo){
		userInfoThreadLocal.set(userInfo);
	}
	
	public static String getToken(){
		return tokenThreadLocal.get();
	}
	
	public static void setToken(String token){
		tokenThreadLocal.set(token);
	}
	
	public static Map<String,String> getScopeLocal(){
		return scopeLocal.get();
	}
	
	public static void setScopeLocal(Map<String,String> scope){
		scopeLocal.set(scope);
	}
	
	
	public static  void remove(){
		requestThreadLocal.remove();
		responseThreadLocal.remove();
		resBeanThreadLocal.remove();
		userInfoThreadLocal.remove();
		tokenThreadLocal.remove();
		scopeLocal.remove();
	}
	
	


}
